//
//  NSString+Ext.m
//  BaseTdkc
//
//  Created by DavidHuang on 16/7/1.
//  Copyright © 2016年 黄栋炜. All rights reserved.
//

#import "NSString+Ext.h"

@implementation NSString (Ext)
+ (NSString*)jsonStrWithData:(id)data {
    if (!data) {
        return @"";
    }
    NSError *parseError = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:NSJSONWritingPrettyPrinted error:&parseError];
    if (parseError) {
        NSLog(@"jsonStrng parse error");
    }
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
+ (NSMutableAttributedString *)addAtributeWithLineSpace:(CGFloat)lineSpace text:(NSString *)text {
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:text];;
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    
    [paragraphStyle setLineSpacing:lineSpace];
    
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, text.length)];
    
    return attributedString;
}

+ (NSMutableAttributedString *)addAtributeWithColor:(UIColor *)color
                                               font:(UIFont *)font
                                              range:(NSRange)range
                                               text:(NSString *)text {
    if (text == nil) {
        return [[NSMutableAttributedString alloc] initWithAttributedString:[[NSAttributedString alloc] initWithString:@""]];
    }
    NSMutableAttributedString *mAstr = [[NSMutableAttributedString alloc]initWithString:text];
    
    NSDictionary *attrs = @{NSFontAttributeName:font,NSForegroundColorAttributeName:color};
    [mAstr addAttributes:attrs range:range];
    
    return mAstr;
}
@end
